
  
  //var opportunityStore=CRM.commons.createStore('opportunityReportStoreId',CRM.SPComp.opportunityDataArray,'opportunityreports/showOpportunityDynamically');
  var searchPeriodStore=CRM.commons.createComboStore('searchPeriodStoreid','opportunityreports/searchPeriodTypes','');
  var statusStore=CRM.commons.createComboStore('statusStoreid','opportunityreports/statusTypes','');
  var stageStore=CRM.commons.createComboStore('stageStoreid','opportunityreports/stageTypes' ,'');
  
  
  CRM.SPComp.createOpportunityDynamicSearch = function(gridId, dataStore, columnModel) {
	  
  var searchCriteriaPanel = {
		xtype	: 'fieldset',	
		width	: 1065,
		title	: 'Selection Criteria',
		items	: [{
		     	    	xtype		: 'compositefield',
		     	    	width		: 600,
		     	    	fieldLabel 	: 'Period',
		     	    	labelWidth 	: 60,
		     	    	items		: [{
			     	    	     	    	xtype 		: 'combo',
			     	    	     	    	id         	: 'searchPeriodType',
			     	    	     	    	hiddenName  : 'searchPerioTypeHiddenName',
			     	                        store		: searchPeriodStore,
			     	                        displayField: 'criteria',
			     	                        valueField  : 'id',
			     	                        triggerAction:'all',
			     	                        editable 	: false,
			     	                        listeners	: {
			     	                        				 select : function(){
			     	                        					 		showPeriod();
			     	                        				 		  }
			     	                        			  }
			     	    	     	    },
			     	    	     	    {	xtype	: 'displayfield', value : 'From: ', width : 50},
			     	    	     	    {
			     	    	     	    	xtype	: 'datefield',
			     	    	     	    	id		: 'fromDate'	
			     	    	     	    },
			     	    	     	    {	xtype	: 'displayfield', value : 'To: ', width : 20},
			     	    	     	    {
			     	    	     	    	xtype	: 'datefield',
			     	    	     	    	id		: 'toDate'
			     	    	     	    }
			     	    	     	  ]
		     	    },
		     	    {
		     	    	xtype		: 'compositefield',
		     	    	width		: 600,
		     	    	fieldLabel 	: 'Status',
		     	    	labelWidth 	: 60,
			     	    items		: [
										{
										     xtype      	: 'combo',
										     id         	: 'statusType',
										     store		    : statusStore,
										     displayField   : 'name',
										     valueField     : 'id',
										     triggerAction  :'all',
										     editable 	    : false
										  },
			     	    	     	  /*  {
			     	    	     	    	xtype      	: 'combo',
			     	                        id         	: 'statusType',
			     	                        store		: statusStore,
			     	                        displayField: 'name',
			     	                        valueField  : 'id',
			     	                        triggerAction:'all',
			     	                        editable 	: false
			     	    	     	    },
			     	    	     	  */  {	xtype	: 'displayfield', value : 'Stage: ', width : 50},
			     	    	     	    {
			     	    	     	    	xtype		: 'combo',
			     	                        id         	: 'stageType',
			     	                        store		:  stageStore,
			     	                        displayField: 'name',
			     	                        valueField  : 'id',
			     	                        triggerAction:'all',
			     	                        width      	: 225,
			     	                        editable 	: false
			     	    	     	    }
			     	    	     	   ]
		     	    		   
		     	     }],
			     	 buttons : [{
	            	    	xtype	: 'button',
	            	    	text	: 'Run',
	            	    	handler	: function(){
	            	    					var statusCmp = Ext.getCmp('statusType');
	            	    					var stageCmp = Ext.getCmp('stageType');
	            	    					var fromDateCmp = Ext.getCmp('fromDate');
	            	    					var toDateCmp = Ext.getCmp('toDate');
	            	    					
	            	    					var statusValue = statusCmp.getValue();
	            	    					var stageValue = stageCmp.getValue();
	            	    					var fromDateValue = fromDateCmp.getValue();
	            	    					var toDateValue   = toDateCmp.getValue();
	            	    					
                       						//var searchGrd = Ext.getCmp('opportunitiesReportSearchGrid');
	            	    					var searchGrd = Ext.getCmp(gridId);
                       						
                       				    	searchGrd.store.removeAll();
                       				    	searchGrd.store.reload({
                       				        			params: {
                       				        						statusType	: statusValue,
                       				        						stageType   : stageValue,
                       				        						periodFrom	: fromDateValue,
                       				        						periodTo	: toDateValue
                       				        					}
                       				        		});
	            	    				}
	            	 },
	            	 {
		            	  xtype :'button',
		                  text : 'Print',
		                  handler : function(){
		            		//var griddata=Ext.getCmp('opportunitiesReportSearchGrid').getStore();
		                	var griddata=Ext.getCmp(gridId).getStore();
		            		if(griddata!= null)
		            		CRM.SPComp.showPrintOpportunityWindow(griddata);
		            		
		            		var period = Ext.getCmp('searchPeriodType');
		            		var periodLabel = Ext.getCmp('period');
		            		periodLabel.setText(period.getRawValue());
		            				            		
		            		var fromDate = Ext.getCmp('fromDate'); 
		            		var fromDateLabel = Ext.getCmp('frDate');
		            		fromDateLabel.setText(fromDate.getRawValue());
		            		
		            		var toDate = Ext.getCmp('toDate');	
		            		var toDateLabel = Ext.getCmp('tDate');
		            		toDateLabel.setText(toDate.getRawValue());
		            		
		            		var stage = Ext.getCmp('stageType');	
		            		var stageLabel = Ext.getCmp('stageLabel');
		            		stageLabel.setText(stage.getRawValue());
		            		
		            		var status = Ext.getCmp('statusType');	
		            		var statusLabel = Ext.getCmp('statusLabel');
		            		statusLabel.setText(status.getRawValue());
		            		
		            	 }
		            }]
	};
	var grid = CRM.commons.createGrid(gridId, dataStore, columnModel);
	grid.setHeight(300);	
  	var resultGridPanel = {
  	  		xtype	: 'panel',
  	  		id		: 'resultGridPanel',
  	  		title	: 'Result',
  	  		width	: 1065,
  	  		frame	: true,
  	  		items	: [grid]
  	  	};
  	
  	

	var rootPanel = {
		xtype	: 'panel',	
		id		: 'rootPanel',	
		padding : '5px',	
		frame	: true,
		items	: [searchCriteriaPanel, resultGridPanel]
	};

	return rootPanel;
  	};	
  	
  	




  	
  	
